//
//  ViewController.swift
//  1.6.Displaying Alerts and Action Sheets
//
//  Created by joker on 15/7/21.
//  Copyright (c) 2015年 joker. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    var controller: UIAlertController?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        //MARK: Alert View
//        controller = UIAlertController(title: "Title", message: "Message", preferredStyle: .Alert)
//        let action = UIAlertAction(title: "Next", style: UIAlertActionStyle.Default, handler: {[weak self](paramAction: UIAlertAction!) in
//            if let textFields = self!.controller?.textFields{
//                let theTextFields = textFields as! [UITextField]
//                let userName = theTextFields[0].text
//                println("Your username is \(userName)")
//            }
//            })
//        controller?.addAction(action)
//        controller?.addTextFieldWithConfigurationHandler({(textField: UITextField!) in textField.placeholder = "XXXXXXXXX"})
        
        //MARK:Alert Sheet
        controller = UIAlertController(title: "Choose how you would like to share this photo", message: "You cannot bring back a delete photo", preferredStyle: .ActionSheet)
        
        let actionEmail = UIAlertAction(title: "Vis email", style: UIAlertActionStyle.Default, handler: {(paramAction: UIAlertAction!) in
            println("Send photo via email.")
        })
        
        let actionImessage = UIAlertAction(title: "Via iMessage", style: UIAlertActionStyle.Default, handler: {(paramAction: UIAlertAction!) in
            println("Send photo via imessage")
        })
        
        let actionDelete = UIAlertAction(title: "Delete photo", style: UIAlertActionStyle.Default, handler: {(paramAction: UIAlertAction!) in
            println("Delete photo")
        })
        
        controller!.addAction(actionEmail)
        controller!.addAction(actionImessage)
        controller!.addAction(actionDelete)
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        self.presentViewController(controller!, animated: true, completion: nil)
    }
}

